//
//  QSShareInstanceModel.swift
//  Test
//
//  Created by Mac on 2022/4/1.
//

import RxSwift

class QSShareInstanceModel {
    // MARK: - Property
    
    private static var _shareInstance: QSShareInstanceModel?
    private static var shareInstance: QSShareInstanceModel {
        guard let instance = _shareInstance else {
            _shareInstance = QSShareInstanceModel()
            return _shareInstance!
        }
        
        return instance
    }
    
    // MARK: - Func
    private init() {}
    
    /// 获取单例
    /// - Parameter bag: 单例回收
    /// - Returns: 单例
    static func share(_ bag: DisposeBag? = nil) -> QSShareInstanceModel {
        if let bag = bag {
            bag.insert(shareInstance)
        }
        return shareInstance
    }
    
    /// 销毁
    static func destroy() {
        _shareInstance = nil
    }
}

extension QSShareInstanceModel: Disposable {
    /// 实现Disposable协议方法
    func dispose() {
        destroy()
    }
}
